﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dotNetInteropPlugin.PluginDev;

namespace ManagedTestPlugin2
{
    public partial class OptFrameData : Form
    {
        public OptFrameData()
        {
            InitializeComponent();
        }

        public IMAIMPPlayer player {get;set;}

        public void Initialize(IMAIMPPlayer p)
        {
            player = p;

            OptFrame = new MAIMPOptionFrame();
            OptFrame.FrameCategory = AIMPOptionFramePosition.AIMP_FRAME_POS_PLAYER;
            OptFrame.FrameName = "Test Frame";

            List<Control> TmpCtrls = new List<Control>();

            foreach (Control curCtrl in this.Controls)
            {
                TmpCtrls.Add(curCtrl);
            }

            this.Controls.Clear();
            OptFrame.ControlsContainer.Controls.AddRange(TmpCtrls.ToArray());

            OptFrame.SaveParameters += new EventHandler(OptFrame_SaveParameters);
            OptFrame.LoadParameters += new EventHandler(OptFrame_LoadParameters);

            player.OptionFramesManager.Add(OptFrame);
        }

        void OptFrame_LoadParameters(object sender, EventArgs e)
        {
            int V = player.ConfigurationManager.ReadParameterInt32("TstSec", "IsCheckedParam");
            checkBox1.Checked = (V == 1);
        }

        void OptFrame_SaveParameters(object sender, EventArgs e)
        {
            player.ConfigurationManager.WriteParameter("TstSec", "IsCheckedParam", checkBox1.Checked ? 1 : 0); ;
        }

        MAIMPOptionFrame OptFrame;

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Enabled = checkBox1.Checked;
            OptFrame.NotifyAboutChanges();
        }
    }
}
